package com.ruoyi.cmdb.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cmdb.service.ITbEmployeeService;
import com.ruoyi.cmdb.util.GetId;
import com.ruoyi.cmdb.util.GetTime;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cmdb.domain.TbIdc;
import com.ruoyi.cmdb.service.ITbIdcService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * idcController
 *
 * @author ruoyi
 * @date 2023-01-25
 */
@RestController
@RequestMapping("/cmdb/idc")
public class TbIdcController extends BaseController
{
    @Autowired
    private ITbIdcService tbIdcService;
    @Autowired
    private ITbEmployeeService tbEmployeeService;
    @Autowired
    private ISysUserService userService;

    /**
     * 查询idc列表
     */
    @PreAuthorize("@ss.hasPermi('cmdb:idc:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbIdc tbIdc)
    {
        startPage();
        List<TbIdc> list = tbIdcService.selectTbIdcList(tbIdc);
        return getDataTable(list);
    }

    /**
     * 导出idc列表
     */
    @PreAuthorize("@ss.hasPermi('cmdb:idc:export')")
    @Log(title = "idc", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbIdc tbIdc)
    {
        List<TbIdc> list = tbIdcService.selectTbIdcList(tbIdc);
        ExcelUtil<TbIdc> util = new ExcelUtil<TbIdc>(TbIdc.class);
        util.exportExcel(response, list, "idc数据");
    }

    /**
     * 获取idc详细信息
     */
    @PreAuthorize("@ss.hasPermi('cmdb:idc:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tbIdcService.selectTbIdcById(id));
    }

    /**
     * 新增idc
     */
    @PreAuthorize("@ss.hasPermi('cmdb:idc:add')")
    @Log(title = "idc", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbIdc tbIdc)
    {
        //生成id
        GetId getId=new GetId();
        String id=getId.getTimeId();
        tbIdc.setId(id);

        GetTime getTime = new GetTime();
        tbIdc.setCreatetTime(getTime.getTimeString15());
        System.out.print(tbIdc);
        return toAjax(tbIdcService.insertTbIdc(tbIdc));
    }

    /**
     * 修改idc
     */
    @PreAuthorize("@ss.hasPermi('cmdb:idc:edit')")
    @Log(title = "idc", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbIdc tbIdc)
    {
        System.out.println(tbIdc);
        return toAjax(tbIdcService.updateTbIdc(tbIdc));
    }

    /**
     * 删除idc
     */
    @PreAuthorize("@ss.hasPermi('cmdb:idc:remove')")
    @Log(title = "idc", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbIdcService.deleteTbIdcByIds(ids));
    }
}
